package ratons.racleurs.main;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.Toast;


public class MainActivity extends Activity
{
	
	public AutoCompleteTextView autoComplete ;
	public ArrayList<String> villes ;
	
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button Valider = (Button) findViewById(R.id.boutonValider);
        
        Valider.setOnClickListener(validerListener);
        
        villes = new ArrayList<String>();
        villes.add("Strasbourg");
        villes.add("Mulhouse");
        
		autoComplete = (AutoCompleteTextView) findViewById(R.id.rechercheVille);
        
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, villes);

        autoComplete.setAdapter(adapter);
    	
    }
    
    private OnClickListener validerListener = new OnClickListener() 
    {
    	public void onClick(View v) 
    	{
    		if(!autoComplete.getText().toString().equals("")){
    			if(villes.contains(autoComplete.getText().toString())){
		    		Bundle donnees = new Bundle();
		    		donnees.putString("ville", autoComplete.getText().toString());
		    		
		    		Intent intent = new Intent(MainActivity.this, ChoixActivity.class);
		    		
		    		intent.putExtras(donnees);
		    		startActivity(intent);
    			} else {
    				Toast.makeText(MainActivity.this, R.string.erreurVille, 3).show();
    			}
    		} else {
    			Toast.makeText(MainActivity.this, R.string.erreurVide, 3).show();
    		}
    	}
    };

}